from __future__ import print_function, absolute_import, unicode_literals
from gm.api import *
import time
from flask import Flask, jsonify, request

app = Flask(__name__)

# 从掘金量化获取数据
@app.route('/api/getData', methods=['GET'])
def getData():
    downLoadPath = request.args.get('downLoadPath')
    # SHSE.000300
    symbol = request.args.get('symbol')
    start_time = request.args.get('start_time')
    end_time = request.args.get('end_time')
    # 终端开启 设置token
    set_token('b9b9a5098c47e70c743d0a811275ff910c1b24cd')
    # 查询历史行情数据，并以结构方式返回'2010-07-28'----'2017-07-30'
    print("symbol:"+symbol)
    print( "start_time:" + start_time )
    print( "end_time:" + end_time)
    history_data = history(symbol=symbol, frequency='1d', start_time=start_time, end_time=end_time,
                           df=True)
    history_data.to_csv(downLoadPath)
    return jsonify(downLoadPath)


if __name__ == '__main__':
    app.run(debug=True)
